package gentle.controller;

import com.baomidou.mybatisplus.plugins.Page;
import gentle.base.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import gentle.entity.SearchCustomerInfo;
import gentle.entity.CustomerInfo;
import gentle.service.IArrearsCustomerService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import gentle.factory.PageFactory;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;

/**
 * @author py
 * @Date 2018年4月19日23:15:54
 */
@Controller
@RequestMapping("/arrearsCustomer")
public class ArrearsCustomerController  extends BaseController {
    @Autowired
    IArrearsCustomerService service;

    /**
     * 欠费患者管理列表
     */
    @RequestMapping("/list")
    @ResponseBody
    public Object list(SearchCustomerInfo info, HttpServletRequest request) {
        Page<CustomerInfo> page = new PageFactory<CustomerInfo>().defaultPage();
        try {
            info.setStartIndex(page.getSize() * (page.getCurrent() - 1));
            info.setLimitIndex(page.getSize());
            page.setCurrent(0);
            List<CustomerInfo> list = service.selectPageListByQueryGetMap(page, info);
            if (list.size() == 0) {
                info.setStartIndex(0);
                list = service.selectPageListByQueryGetMap(page, info);
            }
            page.setTotal(service.getQueryPagesCount(page, info));
            page.setRecords(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return super.packForBT(page);
    }

    @RequestMapping("/sumarrearsCustomer")
    @ResponseBody
    public HashMap sumarrearsCustomer(@RequestParam(required = false) String reach, @RequestParam(required = false) String startArrivalTime,
                                      @RequestParam(required = false) String endArrivalTime,@RequestParam(required = false) String abbreviation) {
        return service.sumarrearsCustomer(reach,startArrivalTime,endArrivalTime,abbreviation);
    }
}